import numpy as np
import pandas as pd

class feature_repository(object):
    def __init__(self):
        pass

    # @staticmethod
    # def current_real_price(dataframe):
    #     return dataframe["成交价"]

    def price_diff_one(dataframe):
        # 添加特征
        series = dataframe["成交价"].diff(-1).fillna(0)
        return series

    @staticmethod
    def volume_diff_one(dataframe):
        # 添加特征
        # print(dataframe.columns)
        series = dataframe["成交量"].diff(-1).fillna(0)/ dataframe["成交量"].rolling(window=5).mean()
        return series

    @staticmethod
    def macd_mark_standard(dataframe):
        EMA_fast = dataframe['成交价'].ewm(span=26, adjust=False).mean()
        EMA_slow = dataframe['成交价'].ewm(span=12, adjust=False).mean()
        macd = EMA_fast - EMA_slow
        signal = macd.ewm(span=9, adjust=False).mean()
        series = (macd - signal).fillna(0)
        return series

    @staticmethod
    def bstotal_volume_ratio(dataframe):
        series = ((dataframe["B1量"]+dataframe["B2量"]+dataframe["B3量"]+dataframe["B4量"]+dataframe["B5量"]) /
                  (dataframe["S1量"]+dataframe["S2量"]+dataframe["S3量"]+dataframe["S4量"]+dataframe["S5量"]))
        return series

    @staticmethod
    def volumn_window_five(dataframe):
        series = dataframe["成交量"].rolling(window=5).mean() / dataframe["成交量"].rolling(window=10).mean()
        return series

    @staticmethod
    def buy_volumn_ratio(dataframe):
        series = ((dataframe["B1量"] + dataframe["B2量"] + dataframe["B3量"] + dataframe["B4量"] + dataframe["B5量"]) /
                dataframe["成交量"].rolling(window=5).mean())
        return series

    @staticmethod
    def sell_volumn_ratio(dataframe):
        series = ((dataframe["S1量"] + dataframe["S2量"] + dataframe["S3量"] + dataframe["S4量"] + dataframe["S5量"]) /
                dataframe["成交量"].rolling(window=5).mean())
        return series

    @staticmethod
    def volumn_window_fifteen(dataframe):
        series = dataframe["成交量"].rolling(window=15).mean() / dataframe["成交量"].rolling(window=10).mean()
        return series

